<template>
  <div>
    <!--头部区域-->
    <div style="height: 60px; line-height: 60px; background-color: white; margin-bottom: 2px;display: flex">
      <div style="width: 300px">
        <img src="@/assets/logo.png" alt="logo"
             style="width: 40px; height: 40px; position: relative; top: 10px; left: 10px">
        <span style="margin-left: 25px;font-size: 24px;">图书管理系统</span>
      </div>

      <!--退出按钮-->
      <div style="flex: 1;text-align: right;padding-right: 20px;">
        <el-dropdown size="medium" style="cursor: pointer">
            <span class="el-dropdown-link">
              {{ admin.username }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
          <el-dropdown-menu slot="dropdown" style="margin-top: -5px">
            <el-dropdown-item>
              <div style="width: 50px;text-align: center" @click="logout">
                退出
              </div>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>


    </div>

    <!--侧边栏和主体-->
    <div style="display: flex;">
      <!--侧边栏导航-->
      <div style="width: 200px; min-height:calc(100vh - 62px); overflow:hidden; margin-right: 2px; background-color: white">
        <el-menu style="min-height: 100%; overflow-x: hidden"
                 background-color="rgb(48, 65, 86)"
                 text-color="#fff"
                 active-text-color="#ffd04b"
                 router
        >
          <el-menu-item index="/">
            <i class="el-icon-s-home"></i>
            <span>首页</span>
          </el-menu-item>

          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-user"></i>
              <span>会员管理</span>
            </template>
            <el-menu-item index="user">会员列表</el-menu-item>
            <el-menu-item index="addUser">会员添加</el-menu-item>
          </el-submenu>

          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-collection"></i>
              <span>图书管理</span>
            </template>
            <el-menu-item index="book">图书列表</el-menu-item>
            <el-menu-item index="addBook">添加图书</el-menu-item>
          </el-submenu>

          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-shopping-bag-1"></i>
              <span>借书管理</span>
            </template>
            <el-menu-item index="borrow">借书列表</el-menu-item>
            <el-menu-item index="addBorrow">借书添加</el-menu-item>
          </el-submenu>

          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-mouse"></i>
              <span>还书管理</span>
            </template>
            <el-menu-item index="returnbook">还书列表</el-menu-item>
          </el-submenu>

          <el-submenu index="5">
            <template slot="title">
              <i class="el-icon-files"></i>
              <span>图书分类管理</span>
            </template>
            <el-menu-item index="category">图书分类列表</el-menu-item>
            <el-menu-item index="addCategory">图书分类添加</el-menu-item>
          </el-submenu>

          <el-submenu index="6">
            <template slot="title">
              <i class="el-icon-monitor"></i>
              <span>管理员管理</span>
            </template>
            <el-menu-item index="admin">管理员列表</el-menu-item>
            <el-menu-item index="addAdmin">管理员添加</el-menu-item>
          </el-submenu>

        </el-menu>
      </div>

      <!--主体数据,width: 0可以限制容器的宽度，不被子元素无限撑开-->
      <div style="flex: 1;width: 0; background-color: white; padding: 10px">
        <router-view/>
      </div>

    </div>
  </div>
</template>

<script>
import Cookies from 'js-cookie';

export default {
  name: "Layout",
  data() {
    return {
      admin: Cookies.get('admin') ? JSON.parse(Cookies.get('admin')) : {}
    }
  },
  methods: {
    logout() {
      //清除浏览器的管理员的数据缓存
      Cookies.remove('admin')
      //点击退出，跳转到登陆页面
      this.$router.push('/login')
    }
  }
}
</script>
